echo "拉取最新代码"
git pull
if [ $? -ne 0 ]; then
    echo "代码拉取失败"
    exit 1
fi
echo "停止8080端口的jar包"
pids=$(ps -eo pid,stat,command | awk '/[j]ava.*8080/ && $2 !~ /Z/ {print $1}')
if [ -n "$pid" ]; then
    kill -9 $pid
    if [ $? -ne 0 ]; then
        echo "停止jar包失败"
        exit 1
    fi
fi

cd java/biz
echo "打包项目"
mvn clean package
if [ $? -ne 0 ]; then
    echo "打包失败"
    exit 1
fi

jar_file=$(ls target/*.jar | tail -n 1)

echo "启动jar包"
nohup java -jar $jar_file & tail -f /dev/null
echo "启动成功"
